package cn.botter.wechat.handler;

import org.springframework.beans.factory.InitializingBean;
import org.springframework.stereotype.Component;

import javax.annotation.Resource;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * @BelongsProject: bo-club
 * @BelongsPackage: cn.botter.wechat.handler
 * @Author: 爱写Bug的Botter
 * @CreateTime: 2025-03-21:22:30
 * @Description: 描述
 * @Version: 1.0
 */
@Component
public class WechatMsgFactory implements InitializingBean {


    @Resource
    private List<WeChatMsgHandler> weChatMsgHandlerList;
    private Map<WeChatMsgTypeEnum, WeChatMsgHandler> weChatMsgHandlerMap = new HashMap<>();

    public WeChatMsgHandler getWeChatMsgHandler(String msgType) {
        WeChatMsgTypeEnum msgHandler = WeChatMsgTypeEnum.getByMsgType(msgType);
        return weChatMsgHandlerMap.get(msgHandler);
    }
    @Override
    public void afterPropertiesSet() throws Exception {
        for (WeChatMsgHandler msgHandler : weChatMsgHandlerList) {
            weChatMsgHandlerMap.put(msgHandler.getMsgType(), msgHandler);
        }
    }
}
